package io.grpc.benchmarks.histogram;

/**
 * http://psy-lob-saw.blogspot.sg/2015/02/hdrhistogram-better-latency-capture.
 * html
 */
class LinearBucketHistogram {
    long[] counters;
    long bucketSize;

    LinearBucketHistogram(long maxTrackableValue, long resolution) {
        bucketSize = resolution;
        counters = new long[(int) (maxTrackableValue / bucketSize + 1)];
    }

    void record(long val) {
        counters[(int) (val / bucketSize)]++;
    }

    public static void main(String args[]) {

        LinearBucketHistogram histogram = new LinearBucketHistogram(1000000, 5);

        for (int i = 0; i < 1000000; i++) {
            histogram.record(i);
        }
    }
}